package com.qiusuo0226.platform.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiusuo0226.platform.mapper.RequestRecordMapper;
import com.qiusuo0226.platform.pojo.dto.RequestRecordPageDTO;
import com.qiusuo0226.platform.pojo.po.RequestRecordPO;
import com.qiusuo0226.platform.pojo.query.RequestRecordQuery;
import com.qiusuo0226.platform.pojo.vo.RequestRecordVO;
import com.qiusuo0226.platform.service.RequestRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


/**
 * 接口访问记录逻辑层
 * @author qiusuo
 * @date 2023/4/6 11:42
 */
@Service
@Slf4j
public class RequestRecordServiceImpl extends ServiceImpl<RequestRecordMapper, RequestRecordPO> implements RequestRecordService {


    @Override
    public void insertRecord(RequestRecordPO record) {
        int insert = baseMapper.insert(record);
        log.debug("insert: {} 条", insert);
    }

    @Override
    public RequestRecordPageDTO selectRecord(RequestRecordQuery query) {
        log.debug("query: {}", query.toString());

        Page<RequestRecordVO> page = new Page(query.getPageNo(), query.getPageSize());
        IPage<RequestRecordVO> iPage = baseMapper.selectRecord(page, query);

        // 封装前端返回数据
        RequestRecordPageDTO requestRecordPageDTO = new RequestRecordPageDTO();
        requestRecordPageDTO.setPageNo(iPage.getCurrent());
        requestRecordPageDTO.setPageSize(iPage.getSize());
        requestRecordPageDTO.setTotal(iPage.getTotal());
        requestRecordPageDTO.setLists(iPage.getRecords());
        return requestRecordPageDTO;
    }
}
